﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;

namespace Erau
{
    public partial class ErauEngine
    {
        public void Save(int slotID)
        {
            IFormatter formatter = new BinaryFormatter();
            Stream streamWrite = new FileStream("save" + slotID.ToString() + ".sav", FileMode.Create, FileAccess.Write, FileShare.None);
            formatter.Serialize(streamWrite, this.gameData);
            streamWrite.Close();
        }

        public void Load(int slotID)
        {
            // 일단 모든 데이터를 메모리에서 내린다.
            gameData.Clear();

            IFormatter formatter2 = new BinaryFormatter();
            Stream streamRead = new FileStream("save" + slotID.ToString() + ".sav", FileMode.Open, FileAccess.Read, FileShare.None);
            this.gameData = (EraTable)formatter2.Deserialize(streamRead);
            streamRead.Close();
        }
    }
}
